
// init jQuery Datepicker
(function () {
    if (jQuery && jQuery.datepicker) {
        jQuery.datepicker.setDefaults({
            changeMonth: true,
            changeYear: true,
            prevText: "",
            nextText: "",
            firstDay: ASC.Resources.Master.FirstDay,
            dateFormat: ASC.Resources.Master.DatepickerDatePattern,
            dayNamesMin: ASC.Resources.Master.DayNames,
            dayNamesShort: ASC.Resources.Master.DayNames,
            dayNames: ASC.Resources.Master.DayNamesFull,
            monthNamesShort: ASC.Resources.Master.MonthNames,
            monthNames: ASC.Resources.Master.MonthNamesFull
        });
    }
})();

// init API Manager
(function () {
    ServiceManager.init(ASC.Resources.Master.ApiPath);
    ServiceFactory.init({
        responses: {
            isme: ASC.Resources.Master.ApiResponsesMyProfile
        },
        portaldatetime: {
            utcoffsettotalminutes: ASC.Resources.Master.TimezoneOffsetMinutes,
            displayname: ASC.Resources.Master.TimezoneDisplayName
        },
        names: {
            months: ASC.Resources.Master.MonthNamesFull,
            shortmonths: ASC.Resources.Master.MonthNames,
            days: ASC.Resources.Master.DayNamesFull,
            shortdays: ASC.Resources.Master.DayNames
        },
        formats: {
            datetime: ASC.Resources.Master.DateTimePattern,
            time: ASC.Resources.Master.TimePattern,
            date: ASC.Resources.Master.DatePattern
        },
        avatars: {
            small: ASC.Resources.Master.AvatarSmall,
            medium: ASC.Resources.Master.AvatarMedium,
            large: ASC.Resources.Master.AvatarLarge
        },
        supportedfiles: {
            imgs: ASC.Resources.Master.filesViewedImages,
            docs: ASC.Resources.Master.filesViewedDocs
        }
    });
    Teamlab.init();
})();

// init Master page
(function () {
    setTimeout(function () {
        var $menuProductsItem = jQuery("a.menu-products-item");
        $menuProductsItem.tlActionMenu({
            title: $menuProductsItem.filter(".active").text(),
            classname: "page-menu-products"
        });

        jQuery("a.menu-user-item").tlActionMenu({
            title: Teamlab.profile.displayName,
            classname: "page-menu-user"
        });

        jQuery("div.page-menu:first").add("div.content-body:first").tlBlock();

        var cbxSelector = "div.checkbox-wrapper:first",
            $pageContent = jQuery("div.page-content:first"),
            $contentHeader = $pageContent.find("div.content-header:first").removeClass("visibility-hidden"),
            $contentBody = $pageContent.find("div.content-body:first").removeClass("visibility-hidden");

        $contentHeader.find("div.content-toolbox:first").css("marginLeft", $contentHeader.find(cbxSelector).width($contentBody.find(cbxSelector).width()).innerWidth() + "px");

        var btnToolboxRight = 0,
            $pageToolbox = jQuery("div.page-toolbox:first"),
            $btnToolbox = $pageToolbox.find("div.btn-toolbox:first"),
            $firstToggleMenu = $pageToolbox.find("div.toggle-menu:first"),
            $additToggleMenu = $pageToolbox.find("div.toggle-menu:last");

        btnToolboxRight = $additToggleMenu.outerWidth(true);
        $btnToolbox.css("right", btnToolboxRight + "px");
        $firstToggleMenu.css("marginRight", $btnToolbox.outerWidth(true) + btnToolboxRight + "px");

        jQuery(document.body).removeClass("body-preload");
    }, 0);
})();
